//
//  BadNetWorkViewController.swift
//  Browser
//
//  Created by 薛永伟 on 2019/5/21.
//  Copyright © 2019 114la.com. All rights reserved.
//

import UIKit

/// 没有网络的VC，不做任何和网络相关的逻辑，仅仅UI效果，任何地方需要展示的地方，添加vc.view即可。
class BadNetWorkViewController: UIViewController {

    
    lazy var imgView: UIImageView = {
        let view = UIImageView()
        view.contentMode = UIView.ContentMode.scaleAspectFit
        view.image = UIImage.init(named: "main_badNetWork_404icon")
        return view
    }()
    
    lazy var descLabel: UILabel = {
        let view = UILabel()
        view.text = "网络被外星人屏蔽了"
        view.textAlignment = .center
        view.textColor = UIColor.init(rgb: 0x999999)
        view.font = UIFont.systemFont(ofSize: 13)
        return view
    }()
    
    lazy var retryBtn: UIButton = {
        let view = UIButton.init(type: .custom)
        view.setTitle("重试", for: .normal)
        view.titleLabel?.font = UIFont.systemFont(ofSize: 15, weight: .regular)
        view.setTitleColor(UIColor.init(rgb: 0x3585FF), for: .normal)
        view.setBackgroundImage(UIImage.init(named: "main_badNetWork_retryIcon"), for: .normal)
        view.addTarget(self, action: #selector(onRetryBtnClick(sender:)), for: .touchUpInside)
        return view
    }()
    
    var retryBtnClickHandle:(()->())?
    
    override func viewDidLoad() {
        
        super.viewDidLoad()

        view.backgroundColor = .white
        customSubviews()
    }
    

    func customSubviews(){
        
        view.addSubview(imgView)
        imgView.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview().offset(-156*0.5)
            make.centerX.equalToSuperview()
            make.width.equalTo(190)
            make.height.equalTo(176)
        }
        
        view.addSubview(descLabel)
        descLabel.snp.makeConstraints { (make) in
            make.centerX.equalTo(imgView)
            make.bottom.equalTo(imgView.snp.bottom).offset(-2.5)
        }
        
        view.addSubview(retryBtn)
        retryBtn.snp.makeConstraints { (make) in
            make.centerX.equalTo(imgView.snp.centerX).offset(0)
            make.top.equalTo(imgView.snp.bottom).offset(37.5)
            make.height.equalTo(35)
            make.width.equalTo(120)
        }
    }
    
    @objc func onRetryBtnClick(sender:UIButton){
        
        retryBtnClickHandle?()
    }

}
